/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.jrill.sample;

import java.util.HashMap;
import org.jrill.User;
import org.jrill.Workflow;
import org.jrill.WorkflowEngine;
import org.jrill.notification.MessageTemplate;
import org.jrill.notification.MessageTemplateFactory;

/**
 * Scenario:
 * (1)Issue document by issuer
 * (2)Sequencially confirmed by two confirmers
 * (3)Received by one of three receptors
 * (4)Concurrently confirmed by three confirmers
 * (5)Done.
 * @author K.Waga
 */
public class SampleWorkflowServiceImpl implements SampleWorkflowService {
    
    private MessageTemplateFactory messageTemplateFactory;
    
    private WorkflowEngine workflowEngine;
    
    public void issue(SampleWorkflowVO vo) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * 
     * @param vo 
     */
    public void proceed(SampleWorkflowVO vo) {
        Workflow wf = getWorkflowEngine().get(vo.getWorkflowId());
        User u = new User(vo.getUserId(), vo.getUserName(), vo.getMailAddress());
        MessageTemplate msg = getMessageTemplateFactory().compose();
        HashMap map = new HashMap();
        map.put("name", vo.getUserName());
        map.put("documentId", vo.getDocumentId());
        msg.setContext(map);
        wf.proceed(u, vo.getNote(), msg);
    }

    public void decline(SampleWorkflowVO vo) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void reject(SampleWorkflowVO vo) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * @return the messageTemplate
     */
    public MessageTemplate getMessageTemplate() {
        return getMessageTemplateFactory().compose();
    }

    /**
     * @return the messageTemplateFactory
     */
    public MessageTemplateFactory getMessageTemplateFactory() {
        return messageTemplateFactory;
    }

    /**
     * @param messageTemplateFactory the messageTemplateFactory to set
     */
    public void setMessageTemplateFactory(MessageTemplateFactory messageTemplateFactory) {
        this.messageTemplateFactory = messageTemplateFactory;
    }

    /**
     * @return the workflowEngine
     */
    public WorkflowEngine getWorkflowEngine() {
        return workflowEngine;
    }

    /**
     * @param workflowEngine the workflowEngine to set
     */
    public void setWorkflowEngine(WorkflowEngine workflowEngine) {
        this.workflowEngine = workflowEngine;
    }
    
}
